package com.example.controller;
import com.example.common.Result;
import com.example.entity.Rule;
import com.example.entity.Scholarship;
import com.example.mapper.RuleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/rule")
public class RuleController {

    @Autowired

    RuleMapper ruleMapper;

    //依然是参考视频，按照学生表进行修改。主要实现rule表的增删改查
    
    @GetMapping("/page")  //分页
    public Result selectAll(@RequestParam String rule_name, @RequestParam Integer start, @RequestParam Integer pageSize)
    {
        List<Rule> ruleList = ruleMapper.selectPage(rule_name,start,pageSize);
        Integer total = ruleMapper.selectTotal(rule_name);
        Map<String ,Object> map = new HashMap<>();
        map.put("list",ruleList);
        map.put("total",total);
        return Result.success(map);
    }


    @PostMapping("/save")
    public Result save (@RequestBody Rule rule){
        ruleMapper.insert(rule);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody Rule rule){
        ruleMapper.update(rule);
        return Result.success();
    }

    @DeleteMapping("/delete")
    public Result delete(@RequestParam  Integer rule_no){
        ruleMapper.delete(rule_no);
        return Result.success();


    }



}
